package online.hxstart.code.concurrent.chapter06;

import java.util.concurrent.TimeUnit;

/**
 * @author huxing
 * @date 19-5-31 星期五 下午4:51
 * @describe 复制线程
 */
public class ThreadGroupEnumerateThreads {

  public static void main(String[] args) throws InterruptedException {
    ThreadGroup myGroup = new ThreadGroup("myGroup");
    Thread thread = new Thread(myGroup, () -> {
      while (true) {
        try {
          TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }, "myThread");
    thread.start();

    TimeUnit.MILLISECONDS.sleep(2);
    ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();

    Thread[] list = new Thread[mainGroup.activeCount()];
    int recurseSize = mainGroup.enumerate(list);
    System.out.println(recurseSize);

    recurseSize = mainGroup.enumerate(list, false);
    System.out.println(recurseSize);
  }
}
